package seatiger.tomcat.util.net;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * ServerSocket工厂，负责创建ServerSocket 和接收连接
 */
public abstract class ServerSocketFactory {
    private static ServerSocketFactory theFactory;

    public static synchronized ServerSocketFactory getDefault() {
        if (theFactory == null) {
            synchronized (ServerSocketFactory.class) {
                if (theFactory == null) {
                    theFactory = new DefaultServerSocketFactory();
                }
            }
        }
        return theFactory;
    }

    public abstract ServerSocket createSocket(int port) throws IOException, InstantiationException;

    public abstract Socket acceptSocket(ServerSocket socket) throws IOException;
}
